package com.aiyige.utils;

import android.text.TextUtils;

import com.aiyige.base.api.JsonUtil;
import com.aiyige.model.request.GetDeafultConponRequest;
import com.aiyige.model.response.ErrorResponse;
import com.aiyige.page.coupon.model.Coupon;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class TestCodeUtil {

    private void requestGetDefaultCoupon(String momentId, float fullAmount) {
        GetDeafultConponRequest.newBuilder().momentId(momentId).fullAmount(fullAmount).build().enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    if (response != null && response.isSuccessful()) {
                        Coupon coupon = JsonUtil.toObject(response.body().string(), Coupon.class);
                        if (coupon != null) {

                        }
                    } else {
                        ErrorResponse data = JsonUtil.toObject(response.errorBody().string(), ErrorResponse.class);
                        onFailure(call, new Throwable(data.getMessage()));
                    }
                } catch (Exception e) {
                    onFailure(call, e);
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                if (t != null && !TextUtils.isEmpty(t.getMessage())) {
                    ToastX.show(t.getMessage());
                }
            }
        });
    }
}
